<script type="text/javascript">
	var asInitVals = new Array();
	$(document).ready(function() {
		var oTable = $('#data').dataTable({
			"bJQueryUI": true,
			"sPaginationType": "full_numbers",
			"aaSorting": [ [1,'asc'] ],
			"sDom": 'T<"H"lfr>t<"F"ip>',
			"oTableTools": {
			"aButtons": [
				{
					"sExtends": "copy",
					"sButtonText": "Copiar",
					"mColumns": [0, 1, 2, 3, 4]
				},
				{
					"sExtends": "print",
					"sButtonText": "Imprimir"
				},
				{
					"sExtends":    "collection",
					"sButtonText": "Guardar como",
					"aButtons":    [
						{
							"sExtends": "xls",
							"mColumns": [0, 1, 2, 3, 4]
						},
						{
							"sExtends": "pdf",
							"sPdfOrientation": "landscape",
							"mColumns": [0, 1, 2, 3, 4],
							"sPdfMessage": "Lista de productos"
						}
					]
				}
			]
			}
        });

        $("tfoot input").keyup( function () {
        	oTable.fnFilter( this.value, $("tfoot input").index(this) );
    	});

		$("tfoot input").each( function (i) {
        	asInitVals[i] = this.value;
    	} );
     
    	$("tfoot input").focus( function () {
        	if ( this.className == "search_init" )
        	{
            	this.className = "";
            	this.value = "";
        	}
    	});
     
    	$("tfoot input").blur( function (i) {
        	if ( this.value == "" )
        	{
            	this.className = "search_init";
            	this.value = asInitVals[$("tfoot input").index(this)];
        	}
    	});
    });
</script>
<a href="../Vendedores/nuevo" class="DTTT_button ui-state-default" style="float:right; margin-bottom:7px;">
	<span>Nuevo Vendedor</span>
</a>
<table cellpadding="0" cellspacing="0" border="0" class="display" id="data">
    <thead>
        <tr>
        	<th>Usuario</th>
			<th>Nombre</th>
			<th>Apellido</th>
			<th>Correo</th>
			<th>Rol</th>
			<th>Acciones</th>
        </tr>
    </thead>
    <tbody>
    <?php $i=0; ?>
	<?php foreach ($vendedores as $v) { ?>
		<tr <?php if($v['Vendedore']['estado'] == 0){ echo 'style="color:#888 !important;"'; } ?>>
			<td style="vertical-align:middle;">
			<?php 
				foreach ($usuarios as $u) {
					if($u['Usuario']['id']==$v['Vendedore']['usuarios_id'])
					echo $u['Usuario']['usuario']; 
		    	} 
			?>
			</td>
			<td style="vertical-align:middle;"><?php echo $v['Vendedore']['nombre']; ?></td>
			<td style="vertical-align:middle;"><?php echo $v['Vendedore']['apellido']; ?></td>
			<td style="vertical-align:middle;"><?php echo $v['Vendedore']['correo']; ?></td>
			<td style="vertical-align:middle;">
			<?php  
				foreach ($usuarios as $u) {
					if($u['Usuario']['id']==$v['Vendedore']['usuarios_id']){
						if($u['Usuario']['rol']==0){
							echo "Vendedor"; 
						}
					}
	    	    } 
			?>
			</td>
			<td style="text-align:center; vertical-align:middle; height:22px;">
				<div style="position:fixed;z-index:999">
					<div id="editmenu<?php echo $i;?>" style="display:none;position:absolute;left:23px;top:20px;background:url('../css/images/blueprint.png')#fff;border:1px solid #ccc;border-radius:5px;width:135px;padding:8px;text-align:left;font-weight:bold;">
						<div style="background:#f4f4f4;border:1px solid #ccc;border-radius:5px;width:118px;padding:8px;text-align:left;font-weight:bold;">
							<div><a onmouseover="this.style.textDecoration='underline'" onmouseout="this.style.textDecoration='none'"  href="../Vendedores/editar?id=<?php echo $v['Vendedore']['id']; ?>">Editar Perfil</a></div>
							<div style="padding-top:10px"><a onmouseover="this.style.textDecoration='underline'" onmouseout="this.style.textDecoration='none'" href="../Vendedores/contrasena?id=<?php echo $v['Vendedore']['usuarios_id']; ?>">Cambiar Contrase&ntilde;a</a></div>
						</div>
					</div>
				</div>
				<a class="crud" onclick="$('#editmenu<?php echo $i; ?>').toggle('slow');"><img style="cursor:pointer;" title="editar" width="16px" height="16px" src="../css/images/editar.png"></a>
				<a class="crud" href="../Vendedores/habilitar?id=<?php echo $v['Vendedore']['id']; ?>"><img <?php if($v['Vendedore']['estado'] == 0){ echo 'src="../css/images/habil.png" title="habilitar" width="16px" height="16px"'; }
																																						 else{ echo 'src="../css/images/deshabil.png" title="deshabilitar" width="16px" height="16px"'; } ?>></a>
			</td>
		</tr>
	<?php $i++; ?>
	<?php } ?>
    </tbody>
    <tfoot>
		<tr>
			<th>
				<input type="text" value="Usuario" class="search_init">
			</th>
			<th>
				<input type="text" value="Nombre" class="search_init">
			</th>
			<th>
				<input type="text" value="Apellido" class="search_init">
			</th>
			<th>
				<input type="text" value="Correo" class="search_init">
			</th>
			<th>
				<input type="text" value="Rol" class="search_init">
			</th>
			<th style="text-align: center;">Acciones</th>
		</tr>
	</tfoot>
</table>